import { useCallback, useState } from "react";
import useInterval from "./useInterval";

function useCounter(delay: number) {
  const [count, setCount] = useState(0);

  const onTick = useCallback(() => {
    setCount(c => c + 1);
  }, []);

  useInterval(onTick, delay);

  return count;
}

export default useCounter;
